open Jopruntime
open Jopruntime.Circuit

(* Compteur à n bits *)
let rec counter n i =
  (* Compteur à 1 bit *)
  let count1 a =
    < s,c >
    | s = reg (xor_ a s)
    | c = and_ a s
  in
  if n = 1 then count1 i
  else     < s[0 : n-1], c_out; c_in >
	   | s[0], c_out = count1 c_in
	   | s[1 : n-1], c_in = counter (n-1) i
;;

let main n =
  < incr, out[0 : n-1], c >
    | incr = input "incr" 1

    | out, c = counter n incr

    | (output "out" out)
    | (output "overflow" c)
;;


(* Ligne qu'on pourra retirer plus tard *)
let c = main (int_of_string Sys.argv.(2));;
Printf.printf "Okkk !\n";;
temp_gen (fst c) Sys.argv.(1);;
